<template>
  <div>
    <!-- <Search /> -->
    <el-container>
      <el-container>
        <el-aside width="200px" v-if="maxPermis == 1">
          <SchoolPermission @e-emit="schoolSelect" />
        </el-aside>
        <el-main style="padding-top: 0">
          <Search />
          <List :schoolId="schoolId" />
        </el-main>
      </el-container>
    </el-container>
    <Add :maxPermis="maxPermis" :schoolId="schoolId" />
  </div>
</template>
<script>
// import Bus from '@/utils/bus.js'
export default {
  components: {
    List: () => import('./List.vue'),
    Add: () => import('./Add.vue'),
    Search: () => import('./Search.vue'),
    SchoolPermission: () => import('@/components/schoolPermission/index.vue'),
  },
  data() {
    return {
      maxPermis: 1000, //最大权限
      schoolId: '',
    }
  },
  mounted() {
    this.getSchoolId()
  },
  methods: {
    schoolSelect(v) {
      this.schoolId = v.id
    },
    getSchoolId() {
      //判断角色是否有系统管理员权限
      let { userData } = this.$store.getters
      let arr = userData.menuRoleList.map((v) => v.userType)
      this.maxPermis = Math.min(...arr)
      //权限设置
      if (this.maxPermis > 1) {
        let { deptFullData } = this.$store.getters
        let flatDept = this.flatObj([JSON.parse(JSON.stringify(deptFullData))])
        if (flatDept.length >= 2) {
          this.schoolId = flatDept[1].id
        } else {
          this.warnMsg('该账号未分配校区，请先配置校区')
          return
        }
      }
    },
  },
}
</script>
<style scoped lang="scss">
</style>